package com.lagou.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lagou.dao.PromotionAdMapper;
import com.lagou.domain.PromotioAdVO;
import com.lagou.domain.PromotionAd;
import com.lagou.service.PromotionAdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PromotionAdServiceImpl implements PromotionAdService {


    @Autowired
    private PromotionAdMapper promotionAdMapper;

    /*分页查询广告信息*/
    @Override
    public PageInfo<PromotionAd> findAllPromotionAdByPage(PromotioAdVO promotioAdVO) {

        PageHelper.startPage (promotioAdVO.getCurrentPage (),promotioAdVO.getPageSize ());

        List<PromotionAd> allAdByPage = promotionAdMapper.findAllPromotionAdByPage ();

        PageInfo<PromotionAd> PageInfo = new PageInfo<> (allAdByPage);

        return PageInfo;

    }

    /*广告状态的上下线*/
    @Override
    public void updatePromotionAdStatus(int id, int status) {

        PromotionAd promotionAd = new PromotionAd ();
        promotionAd.setId (id);
        promotionAd.setStatus (status);
        promotionAd.setUpdateTime (new Date ());

        promotionAdMapper.updatePromotionAdStatus (promotionAd);
    }
}
